<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script type="text/javascript">
    //    var Professor = function () {
    //     }
    //             Professor.prototype = {
    //         name: '教授',
    //         //如果原型中有引用值，那么子集能改掉，改的是引用值对应地址中的值
    //         info: {
    //             age: 60
    //         }
    //     }   

    //     var professor = new Professor()
    //     console.log(professor.name);
    //    var Teacher = function () { }
    //     Teacher.prototype = professor  //

    //     Teacher.prototype.tname = '教师'
    //     var teacher = new Teacher();
    //     console.log(teacher);

    // function A() { }
    //     A.prototype.n = 1
    //     var b = new A()
    //     A.prototype = {
    //         n: 2,
    //         m: 3,
    //     }
    //     var c = new A()
    //     console.log(b.n, b.m, c.n, c.m)//1,undefind 2,3
        // function Foo() {
        //     Object.prototype.a = function () {
        //         console.log('可访问a')
        //     }
        // }
        // Function.prototype.b = function () {
        //     console.log('可访问b')
        // }
        // var foo = new Foo()
        // foo.a();//'可访问a'
        // foo.b();//报错
        // Foo.a();//'可访问a'
        // Foo.b();//'可访问b'


        var fun=function(){}
        fun.prototype = {
            name: 'peter',
            age: 25
        }
        var a = new fun();
        var b = new fun();
        console.log(a.name,b.name);//peter peter
        fun.prototype.name='jack';
        console.log(a.name,b.name);//jack jack
        //重写原型

        fun.prototype = {};
        fun.prototype.name = 'tom';
        console.log(a.name,b.name);//jack jack




    </script>
</body>
</html>